
<?php


/* 分类列表递归 */
 function getCate($pid=0,$cate=array(),$level=0){

    $sql = "select * from `cate` where pid=$pid ";

    $result = mysqli_query($GLOBALS['link'],$sql);

    while ($arr=mysqli_fetch_assoc($result)){

      $str = '';
      for ($i=0; $i < $level; $i++) {
        $str .= '●';

      }

      //将星和所查到的数据名称进行拼接，然后替换
      $arr['name'] = $str.$arr['name'];
      $cate[] = $arr;

      $cate = getCate($arr['id'],$cate,$level+1);

    }
    return $cate;
  }



/* 分类编辑递归 */
  function editCate($data,$cate=array()){

    $pid = $data['pid'];

    $arr = getSelect('cate',"pid=$pid");


    foreach ($arr as $v) {

       $cate[$data['id']][]=$v;

    }

    if($pid!=0){
    //查父级
      $data = getSelectByOne('cate',"id= $pid");
      //调用自身，找父级的同级
      $cate = editCate($data,$cate);
    }
                   // 将数组倒叙
    return $cate  ;
  }

